// JavaScript Document
var killScroll = false;
var scrollTop = 0;
var docHeight = 0;
var winHeight = 0;
var scrolltop20 = 0;
var result = 0;

/*####### :: Infinite Scroll Post :: #######*/

function lastPostFunc(page) 
{ 
    var last = $('ul').find("li:last");
    var last_id = last.attr('last_id');

    $.post('validate/'+page+'Data.php',{
        'id': last_id
    },
    function(data)
    {
        if(data != 0)
        {
            last.after(data);		
        }
        else
        {
            console.log('-0-');
            $('#loading').hide();
            $('#loadding-text').hide();					
        }
    }
    );
};

function newSearch(page, wordsearch, newstype) 
{ 
    var last = $('ul').find("li:last");
    var last_id = last.attr('last_id');

    $.post('validate/'+page+'Data.php',
    {
        'id': last_id ,
        'wordSearch': wordsearch, 
        'news_type': newstype,
    },
    function(data)
    {
        if(data != 0)
        {
            last.after(data);		
        }
        else
        {
            console.log('-0-');
            $('#loading').hide();
            $('#loadding-text').hide();					
        }
    }
    );
};

function marketSearch(page, wordsearch, productstatus, categoryid, tradeid, provinceid) 
{ 
    var last = $('ul').find("li:last");
    var last_id = last.attr('last_id');

    $.post('validate/'+page+'Data.php',
    {
        'id': last_id ,
        'wordSearch': wordsearch, 
        'product_status': productstatus,
        'category_id': categoryid,
        'trade_id': tradeid,
        'province_id' : provinceid,
    },
    function(data)
    {
        if(data != 0)
        {
            last.after(data);		
        }
        else
        {
            console.log('-0-');
            $('#loading').hide();
            $('#loadding-text').hide();					
        }
    }
    );
};

function webboardSearch(page, wordsearch, webboardtype) 
{ 
    var last = $('ul').find("li:last");
    var last_id = last.attr('last_id');

    $.post('validate/'+page+'Data.php',
    {
        'id': last_id ,
        'wordSearch': wordsearch, 
        'webboardtype': webboardtype
    },
    function(data)
    {
        if(data != 0)
        {
            last.after(data);		
        }
        else
        {
            console.log('-0-');
            $('#loading').hide();
            $('#loadding-text').hide();					
        }
    }
    );
};

function modifySearch(page, wordsearch, modifytype) 
{ 
    var last = $('ul').find("li:last");
    var last_id = last.attr('last_id');

    $.post('validate/'+page+'Data.php',
    {
        'id': last_id ,
        'wordSearch': wordsearch, 
        'modify_id': modifytype,
    },
    function(data)
    {
        if(data != 0)
        {
            last.after(data);		
        }
        else
        {
            console.log('-0-');
            $('#loading').hide();
            $('#loadding-text').hide();					
        }
    }
    );
};

function gallerySearch(page, wordsearch) 
{ 
    var last = $('ul').find("li:last");
    var last_id = last.attr('last_id');

    $.post('validate/'+page+'Data.php',
    {
        'id': last_id ,
        'wordSearch': wordsearch, 
    },
    function(data)
    {
        if(data != 0)
        {
            last.after(data);		
        }
        else
        {
            console.log('-0-');
            $('#loading').hide();
            $('#loadding-text').hide();					
        }
    }
    );
};

function clubListDetail(page, clubid) 
{ 
    var last = $('ul').find("li:last");
    var last_id = last.attr('last_id');

    $.post('validate/'+page+'Data.php',
    {
        'id': last_id ,
        'clubid': clubid
    },
    function(data)
    {
        if(data != 0)
        {
            last.after(data);		
        }
        else
        {
            console.log('-0-');
            $('#loading').hide();
            $('#loadding-text').hide();					
        }
    }
    );
};

function clubSearch(page, wordsearch) 
{ 
    var last = $('ul').find("li:last");
    var last_id = last.attr('last_id');

    $.post('validate/'+page+'Data.php',
    {
        'id': last_id ,
        'wordSearch': wordsearch, 
    },
    function(data)
    {
        if(data != 0)
        {
            last.after(data);		
        }
        else
        {
            console.log('-0-');
            $('#loading').hide();
            $('#loadding-text').hide();					
        }
    }
    );
};

/*##### :: End Infinite Scroll Post :: #####*/

/*####### :: Infinite Scroll Reply :: #######*/
function lastReply(page, postId, numReply) 
{ 	
    var last_id = $('.countReply:last').data('replyid')
    $.post('validate/'+page+'Data.php',
    { 
        'reply_id': last_id ,
        'post_id': postId,
        'num_reply': numReply
    },
    function(data)
    {		
        if (data != 0) 
        {								
            $('.countReply:last').after(data);
        }
        else
        {
            console.log('-0-');
            $('#loading').hide();
            $('#loadding-text').hide();									
        }
    }
    );
};
/*##### :: End Infinite Scroll Reply :: #####*/



function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
        );
}

function getWinHeight()
{
    var y = 0;
    if (self.innerHeight)
    {
        y = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {
        y = document.documentElement.clientHeight;
    }
    else if (document.body)
    {
        y = document.body.clientHeight;
    }
    return y;
}